home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / w3 / w3-props.el.z / w3-props.el
Encoding:
Text File  |  1998-05-21  |  4.4 KB  |  94 lines

  1. ;;; w3-props.el --- Additional text property stuff
  2. ;; Author: wmperry
  3. ;; Created: 1997/10/17 14:08:20
  4. ;; Version: 1.3
  5. ;; Keywords: faces
  6.  
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;; Copyright (c) 1995, 1996 by William M. Perry <wmperry@cs.indiana.edu>
  9. ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
  10. ;;;
  11. ;;; This file is part of GNU Emacs.
  12. ;;;
  13. ;;; GNU Emacs is free software; you can redistribute it and/or modify
  14. ;;; it under the terms of the GNU General Public License as published by
  15. ;;; the Free Software Foundation; either version 2, or (at your option)
  16. ;;; any later version.
  17. ;;;
  18. ;;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ;;; GNU General Public License for more details.
  22. ;;;
  23. ;;; You should have received a copy of the GNU General Public License
  24. ;;; along with GNU Emacs; see the file COPYING.  If not, write to the
  25. ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  26. ;;; Boston, MA 02111-1307, USA.
  27. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  28.  
  29. ;;; Additional text property functions.
  30.  
  31. ;; The following three text property functions are not generally available (and
  32. ;; it's not certain that they should be) so they are inlined for speed.
  33. ;; The case for `fillin-text-property' is simple; it may or not be generally
  34. ;; useful.  (Since it is used here, it is useful in at least one place.;-)
  35. ;; However, the case for `append-text-property' and `prepend-text-property' is
  36. ;; more complicated.  Should they remove duplicate property values or not?  If
  37. ;; so, should the first or last duplicate item remain?  Or the one that was
  38. ;; added?  In our implementation, the first duplicate remains.
  39.  
  40. (defsubst fillin-text-property (start end setprop markprop value &optional object)
  41.   "Fill in one property of the text from START to END.
  42. Arguments PROP and VALUE specify the property and value to put where none are
  43. already in place.  Therefore existing property values are not overwritten.
  44. Optional argument OBJECT is the string or buffer containing the text."
  45.   (let ((start (text-property-any start end markprop nil object)) next)
  46.     (while start
  47.       (setq next (next-single-property-change start markprop object end))
  48.       (put-text-property start next setprop value object)
  49.       (put-text-property start next markprop value object)
  50.       (setq start (text-property-any next end markprop nil object)))))
  51.  
  52. (defsubst w3-props-unique (list)
  53.   "Uniquify LIST, deleting elements using `delq'.
  54. Return the list with subsequent duplicate items removed by side effects."
  55.   (let ((list list))
  56.     (while list
  57.       (setq list (setcdr list (delq (car list) (cdr list))))))
  58.   list)
  59.  
  60. ;; A generalisation of `facemenu-add-face' for any property, but without the
  61. ;; removal of inactive faces via `facemenu-discard-redundant-faces' and special
  62. ;; treatment of `default'.  Uses `unique' to remove duplicate property values.
  63. (defsubst prepend-text-property (start end prop value &optional object)
  64.   "Prepend to one property of the text from START to END.
  65. Arguments PROP and VALUE specify the property and value to prepend to the value
  66. already in place.  The resulting property values are always lists, and unique.
  67. Optional argument OBJECT is the string or buffer containing the text."
  68.   (let ((val (if (listp value) value (list value))) next prev)
  69.     (while (/= start end)
  70.       (setq next (next-single-property-change start prop object end)
  71.         prev (get-text-property start prop object))
  72.       (put-text-property
  73.        start next prop
  74.        (w3-props-unique (append val (if (listp prev) prev (list prev))))
  75.        object)
  76.       (setq start next))))
  77.  
  78. (defsubst append-text-property (start end prop value &optional object)
  79.   "Append to one property of the text from START to END.
  80. Arguments PROP and VALUE specify the property and value to append to the value
  81. already in place.  The resulting property values are always lists, and unique.
  82. Optional argument OBJECT is the string or buffer containing the text."
  83.   (let ((val (if (listp value) value (list value))) next prev)
  84.     (while (/= start end)
  85.       (setq next (next-single-property-change start prop object end)
  86.         prev (get-text-property start prop object))
  87.       (put-text-property
  88.        start next prop
  89.        (w3-props-unique (append (if (listp prev) prev (list prev)) val))
  90.        object)
  91.       (setq start next))))
  92.  
  93. (provide 'w3-props)
  94.